<template>
  <div>
    <router-link to="/">
      <div class="header-abs">
        <div class="iconfont">&#xe624;</div>
      </div>
    </router-link>
    <div class="header-title" v-show="!showAbs" :style="opacityStyle">
      <router-link tag="div" to="/" class="iconfont title-back">&#xe624;</router-link>
        景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style scoped>
.header-abs{
  position: fixed;
  left: 0.2rem;
  top: 0.2rem;
  width: .8rem;
  height: .8rem;
  border-radius: .4rem;
  background: rgba(0,0,0,.7);
  text-align: center;
  line-height: .8rem;
}
.iconfont{
  color: #ffffff;
}
.header-title{
  width: 100%;
  height: .8rem;
  position: fixed;
  left: 0;
  top: 0;
  color: #ffffff;
  background: #00bcd4;
  text-align: center;
  line-height: .8rem;
  font-size: 0.21rem;
  font-weight: bolder;
  z-index: 100;
}
.title-back{
  position: absolute;
  top: 0;
  left: 0;
}
</style>
